home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3942 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: news.mindlink.net!news
  2. From: genew@mindlink.bc.ca (Gene Wirchenko)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: division problem
  5. Date: Thu, 01 Feb 1996 03:20:34 GMT
  6. Organization: MIND LINK! - British Columbia, Canada
  7. Message-ID: <4epbla$e37@fountain.mindlink.net>
  8. References: <31097D77.11AA@rain.org> <26JAN199622082450@erich.triumf.ca> <4eh246$u6h@airdmhor.gen.nz> <4ej4ha$66@fountain.mindlink.net> <DLzvGG.2rn@uns.bris.ac.uk> <4emuba$1mo@fountain.mindlink.net> <823118692snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: line314.nwm.mindlink.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
  13.  
  14. >In article <4emuba$1mo@fountain.mindlink.net>
  15. >           genew@mindlink.bc.ca "Gene Wirchenko" writes:
  16.  
  17. >>>Still no need to use floating point,
  18. >>>celcius = ((fahrenheit - 32) * 5 + 4) / 9
  19. >>
  20. >>     Let's assume that you had never run across fahrenheit to celsius
  21. >>conversion before (because the above could just as easily be a case of
  22. >>converting flibbles to meeblesnauzers).
  23. >>
  24. >>     Can you derive the ORIGINAL formula for conversion of F to C?
  25. >>
  26. >>     If yes, how?  Because you don't know what the 4 is for.
  27.  
  28. >Maybe not but its effect is clearly one of rounding. Perhaps it would be
  29. >clearer to specify it as (9/2), perhaps not.
  30.  
  31.      Apparently not clearly.  For all you/I/etc. know, the 4 might be
  32. part of the original formula.
  33.  
  34. >>     If no, then it's unclear code, isn't it?
  35.  
  36. >How would you express it more clearly?
  37.  
  38.      It seems it begs for a comment.  This may seem like nitpicking,
  39. but comments are part of a program.
  40.  
  41.      /* Convert degrees Fahrenheit to degrees Celsius using formula:
  42.       * (F-32)*5/9.  The purpose of the added 4 below is for rounding
  43.       * to the nearest degree.
  44.       */
  45.  
  46.      celsius= ...
  47.  
  48.      This is a case where the code isn't obvious, right?  (Assuming
  49. that the formula isn't a common one.)
  50.  
  51.      Not being a Macho Programmer (If it was hard to program, it
  52. should be hard to read, etc.), I like a well-placed comment.
  53.  
  54. >-- 
  55. >-----------------------------------------
  56. >Lawrence Kirby | fred@genesis.demon.co.uk
  57. >Wilts, England | 70734.126@compuserve.com
  58. >-----------------------------------------
  59.  
  60. Sincerely,
  61.  
  62. Gene Wirchenko
  63.  
  64. C Pronunciation Guide:
  65.      y=x++;     "wye equals ex plus plus semicolon"
  66.      x=x++;     "ex equals ex doublecross semicolon"
  67.  
  68.